package com.ang.quartz.springboot.job;

import com.ang.quartz.normal.pojo.Data;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;

/**
 * @author ssang
 * @date 2022-01-07 9:45
 */
public class HiJob extends QuartzJobBean {
    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        System.out.println("=============获取jobDetail参数");
        JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
        //简单参数
        System.out.println(jobDataMap.getString("job_param"));
        //对象参数
        Data data = (Data) jobDataMap.get("job_data");
        System.out.println(String.format("对象类型参数,id:%s,flag:%s",data.getId(),data.getFlag()));

        System.out.println("=============获取trigger参数");
        JobDataMap jobDataMap1 = jobExecutionContext.getTrigger().getJobDataMap();
        //简单参数
        System.out.println(jobDataMap1.getString("job_trigger_param"));
        //对象参数
        Data data1 = (Data) jobDataMap1.get("trigger_data");
        System.out.println(String.format("对象类型参数,id:%s,flag:%s",data1.getId(),data1.getFlag()));
    }
}
